#ifndef _CAMERA_SKYPHOTO_
#define _CAMERA_SKYPHOTO_

#include "Photo.h"
#include "../base/Base.h"

class CCamera;
class CClearSky;

struct CSample
{
	CPixel m_pixel;
	CColor m_color;
};


enum COLOR_INDEX {RED = 0, GREEN, BLUE};
enum PARA_INDEX	{A = 0, B, C, D, E};


class CSkyPhoto : public CPhoto
{
public:
	CSkyPhoto(){};
	CSkyPhoto(char* filename, CCamera* pCamera);
	CSkyPhoto(char* filename, CString imagePath);
	CSkyPhoto(CClearSky* pSky);
	CSkyPhoto(const CSkyPhoto& photo);
	~CSkyPhoto(){};

	void SetSky(CClearSky* pSky);
	CPixel GetPixelSolarPosition() {return m_solarPosition;}

	void CalcPixelSolarPosition();
	void CalcExtrinsicParas();

	void AddSample(CPixel p, CColor c);
	void InitSample() {m_samples.clear();}

	void SaveSamplesIntoFile();
	bool LoadSamplesFromFile();

	void SkyModelFitting();
	void Pixel2SkyModelColor(int x, int y, int &r, int &g, int &b);
	void Glo3DPoint2SkyModelColor(float x, float y, float z, int &r, int &g, int &b);
	void SaveSkyPhoto();

private:
	CPixel m_solarPosition;
	CClearSky* m_pSky;
	bool m_isSunny;
	char m_fileName[256];
	vector<CSample> m_samples;

	CClearSkyParameter m_paras[3];

	float PerezFunction(CClearSkyParameter para, float theta, float gamma);
	float dPda(CClearSkyParameter para, float theta, float gamma);
	float dPdb(CClearSkyParameter para, float theta, float gamma);
	float dPdc(CClearSkyParameter para, float theta, float gamma);
	float dPdd(CClearSkyParameter para, float theta, float gamma);
	float dPde(CClearSkyParameter para, float theta, float gamma);
	float dPdparas(CClearSkyParameter para, float theta, float gamma, PARA_INDEX pindex);
};



#endif